﻿using GameControler.Emgu;
using GameControler.Game;
using PlatformCommon.Manager;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace GameControler
{
    public class AutoFightingView : ViewObject
    {
        public override string FloderName
        {
            get { return "AutoFightingView"; }
        }

        private static AutoFightingView instance;
        public static AutoFightingView Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new AutoFightingView();
                }
                return instance;
            }
        }

        public bool IsAuto { get; set; }

        protected AutoFightingView()
            : base()
        {

        }

        public override bool IsCurrentView(System.Drawing.Bitmap intputbmp)
        {
            Point autopoint = new Point();
            var width = intputbmp.Width;
            var height = intputbmp.Height;
            foreach (var item in this.Templates)
            {
                var x = item.Point.X > 0 ? 0 : intputbmp.Width + item.Point.X;
                var y = item.Point.Y > 0 ? 0 : intputbmp.Height + item.Point.Y;
                var clipbitmap = intputbmp.Clone(new Rectangle(x, y, Math.Abs(item.Point.X), Math.Abs(item.Point.Y)), intputbmp.PixelFormat);
                // clipbitmap.Save(@"c:/1.png");

                var md = JilyEmgu.MatchResult(clipbitmap, item);
                clipbitmap.Dispose();
                if (item.Team == "1" && md.IsMatch)
                {
                    return false;
                }
            }

            Log4Wrap.Logger.Info("AutoFighting界面匹配" + "___" + "当前自动战斗");

            return true;
        }

    }
}
